package org.bmp.zemail.server.common.models;

import java.io.Serializable;
import java.util.List;

import org.bmp.zemail.login.user.models.User;
import org.bmp.zemail.server.credential.models.Credentials;
import org.bmp.zemail.server.folder.models.Folder;

public class Server implements Serializable {

	private static final long serialVersionUID = 1L;

	public enum Type { EXCHANGE_2007, GMAIL }
	public enum Protocol { SMTP, IMAP }
	
	private String id;
	private String name;
	private Type type;
	private Protocol protocol;
	private String url;
	private User user;//belongs to a
	private Credentials credentials;
	private List<Folder> folders;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public Protocol getProtocol() {
		return protocol;
	}

	public void setProtocol(Protocol protocol) {
		this.protocol = protocol;
	}

	public String getUrl() {
		return url;
	}
	
	public void setUrl(String url) {
		this.url = url;
	}
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Credentials getCredentials() {
		return credentials;
	}
	
	public void setCredentials(Credentials credentials) {
		this.credentials = credentials;
	}

	public List<Folder> getFolders() {
		return folders;
	}

	public void setFolders(List<Folder> folders) {
		this.folders = folders;
	}

	public void setProtocol(String protocol) {
		if (Protocol.IMAP.toString().equals(protocol)) {
			setProtocol(Protocol.IMAP);
		} else if (Protocol.SMTP.toString().equals(protocol)) {
			setProtocol(Protocol.SMTP);
		} else {
			//TODO BM houston we have a problem
		}
	}

	public void setType(String type) {
		if (Type.EXCHANGE_2007.toString().equals(type)) {
			setType(Type.EXCHANGE_2007);
		} else if (Type.GMAIL.toString().equals(type)) {
			setType(Type.GMAIL);
		} else {
			//TODO BM houston we have a problem
		}
	}
	
	public Folder getFolder(String folderName) {
		for (Folder folder : folders) {
			if (folder.getName().equals(folderName)) {
				return folder;
			}
		}
		return null;
	}
}
